/*-------------------------------------------------------------------------
* CLR版本:     4.0.30319.42000
* 创建人:      song 
* 创建时间：   2024/4/9 14:47:37
* 功 能：      始终面向摄像机
*-------------------------------------------------------------------------*/

using UnityEngine;

namespace SCore.UI
{
    public class SBillboard : MonoBehaviour
    {
        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
        private static void Initialize()
        {
            _camera = null;
        }

        public Transform _facedObject;

        private Transform activeFacedObject
        {
            get
            {
                if (_facedObject != null) return _facedObject;
                if (_camera != null) return _camera.transform;
                _camera = Camera.main;

                return _camera == null ? null : _camera.transform;
            }
        }

        private static Camera _camera;

        private void Update()
        {
            if (activeFacedObject == null) return;
            transform.LookAt(activeFacedObject);
        }
    }
}